package com.gem.netty.message;

import com.gem.enums.ClientMessageType;
import com.gem.netty.message.robot.AddRobot;

import java.util.HashMap;

/**
 * Author: Xhy
 * CreateTime: 2022-09-21 13:11
 *
 * 用于管理消息类型
 */
public class MessageFactory {

    private static HashMap<Integer,Message> data = new HashMap<>();

    public static Message get(Integer key){
        if (!data.containsKey(key)) {
            throw new IllegalArgumentException("类型不匹配");
        }
        return data.get(key);
    }

    public static void put(Integer key,Message value){
        data.put(key,value);
    }

    static {
        put(ClientMessageType.BIND_CHANNEL.type,new BindChannelGroupMessage());
        put(ClientMessageType.SEND_MESSAGE.type,new ChatRoomMessage());
        put(ClientMessageType.GET_GEM.type,new GetGemMessage());
        put(ClientMessageType.GET_CARD.type,new GetCardMessage());
        put(ClientMessageType.GET_NOBILITY.type,new GetNobilityMessage());
        put(ClientMessageType.QUIT_ROOM.type,new QuitRoomMessage());
        put(ClientMessageType.SKIP_ROUND.type,new SkipRoundMessage());
        put(ClientMessageType.GAME_BEGIN.type,new GameBeginMessage());
        put(ClientMessageType.JOIN_ROOM.type,new JoinRoomMessage());
        put(ClientMessageType.TS.type,new TSMessage());
        put(ClientMessageType.SKIP_GEM_ROUND.type,new SkipGemRoundMessage());
//        put(ClientMessageType.HEART.type,new HearMessage());
        put(ClientMessageType.ADD_ROBOT.type,new AddRobot());

    }
}
